package com.congee02;

/**
 * @author congee02
 * @date 2/1/2023 12:05 PM
 */
public interface ThreadProvider extends Runnable {

    /**
     * 将本对象包装为 Thread
     *
     * @return 包装后的线程对象
     */
    private Thread selfWrap() {
        return new Thread(this);
    }

    /**
     * 将对象包装为一个 Thread 对象返回，设置名称和优先级
     *
     * @param threadName 线程名称
     * @param priority   优先级
     * @return 包装的对象
     */
    default Thread thread(String threadName, int priority) {
        Thread thread = selfWrap();
        thread.setName(threadName);
        thread.setPriority(priority);
        return thread;
    }

    /**
     * 将对象包装为一个 Thread 对象返回，设置名称
     *
     * @param threadName 线程名称
     * @return 包装的对象
     */
    default Thread thread(String threadName) {
        Thread thread = selfWrap();
        thread.setName(threadName);
        return thread;
    }

    /**
     * 将对象包装为一个 Thread 对象返回，设置优先级
     *
     * @param priority 优先级
     * @return 包装的对象
     */
    default Thread thread(int priority) {
        Thread thread = selfWrap();
        thread.setPriority(priority);
        return thread;
    }

    /**
     * 将对象包装为一个 Thread 对象返回
     *
     * @return 包装的对象
     */
    default Thread thread() {
        return selfWrap();
    }

}
